<template>
  <div class="personal">
    <Top />
    <div class="conter-nav">
      <div class="left-nav">
        <div class="users">
          <img src="@/assets/imgs/N1.jpg" alt="" />
          <div class="name">戴用名</div>
        </div>
        <ul class="ul-nav">
          <li
            v-for="(item, index) in usersForm"
            :key="index"
            @click="tapNav(item.id)"
            :class="navId == item.id ? 'active' : ''"
          >
            <router-link :to="item.path">{{ item.name }}</router-link>
          </li>
        </ul>
        <div class="outlogin"><a href="javascript:;">退出账号</a></div>
      </div>
      <div class="right-view">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import Top from "@/components/top.vue";
export default {
  name: "",
  components: {
    Top
  },
  data() {
    return {
      navId: 0,
      usersForm: [
        { id: 0, path: "/core", name: "个人信息" },
        { id: 1, path: "/news", name: "消息中心" },
        { id: 2, path: "/interactive", name: "互动交流" },
        { id: 3, path: "/consult", name: "咨询答疑" },
        { id: 4, path: "/mail", name: "网站邮箱" }
      ]
    };
  },
  beforeRouteEnter: (to, from, next) => {
    if (to.path == "/consult") {
      localStorage.setItem("navId", 3);
      next();
    } else if (to.path == "/mail") {
      localStorage.setItem("navId", 4);
      next();
    } else if (to.path == "/core") {
      localStorage.setItem("navId", 0);
      next();
    } else if (to.path == "/news") {
      localStorage.setItem("navId", 1);
      next();
    } else if (to.path == "/interactive") {
      localStorage.setItem("navId", 2);
      next();
    }
    next(vm => {});
  },
  created() {
    this.navId = localStorage.getItem("navId") || 0;
  },
  methods: {
    tapNav(id) {
      localStorage.setItem("navId", id);
      this.navId = localStorage.getItem("navId");
    }
  }
};
</script>
<style lang="scss" scoped>
.personal {
  background-color: #f4f4f4;
  overflow: hidden;
  position: relative;

  .conter-nav {
    margin-top: 150px;
    display: flex;
    padding: 20px 30px 38px;
    .left-nav {
      height: 726px;
      background: #fff;
      margin-right: 30px;
      border-radius: 5px;
      flex: 1;
      a {
        color: #666666;
      }
      .users {
        display: flex;
        height: 124px;
        padding: 30px 0 0 30px;
        img {
          width: 64px;
          height: 64px;
          border-radius: 50%;
          line-height: 124px;
        }
        .name {
          color: #666666;
          line-height: 67px;
          font-size: 26px;
          margin-left: 30px;
        }
      }
      .ul-nav {
        li {
          width: 98%;
          color: #666666;
          font-size: 22px;
          text-align: center;
          line-height: 80px;
          height: 80px;
          border-radius: 0 5px 5px 0;
          border-left: 6px solid #fff;
          a {
            width: 100%;
            display: block;
            height: 100%;
          }
        }
        .active {
          border-left: 6px solid #b21315;
          background-color: rgba(178, 19, 21, 0.1);
          box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.16);
        }
      }
      .outlogin {
        width: 98%;
        margin-top: 147px;
        text-align: center;
        color: #666666;
        font-size: 22px;
        height: 50px;
      }
    }
    .right-view {
      padding: 0 0 30px;
      flex: 4;
      background: #fff;
      border-radius: 5px;
    }
  }
}
</style>
